package com.permission.myannotation;

import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.springframework.web.method.HandlerMethod;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Created by Administrator on 2018/6/22
 */
@Slf4j
@Component
public class TestIntercepter extends HandlerInterceptorAdapter {

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
            throws Exception {
        if (handler instanceof HandlerMethod) {
            HandlerMethod handlerMethod = (HandlerMethod)handler;
            TestAnnotation testAnnotation = ((HandlerMethod) handler).getMethodAnnotation(TestAnnotation.class);
            if (testAnnotation == null) {
                return true;
            }
            log.info("TestAnnotation value={}", testAnnotation.value());
        }
        return true;
    }
}
